<template>
    <div>
        <Modal v-model="showDataModalFlag" title="修改流程" @on-ok="handleSubmit2('formValidate2')" :mask-closable="false">
            <Form :label-width="100" ref="formValidate2" :rules="ruleValidate2" :model="data2">
                <FormItem label="时间" prop="year">
                    <Input placeholder="时间" class="input-select-class" v-model="data2.time"></Input>
                </FormItem>
                <FormItem label="内容" prop="operate_name2">
                    <Input placeholder="地点" class="input-select-class" v-model="data2.content"></Input>
                </FormItem>
                <FormItem label="图标">
                    <Select style="width:100%" v-model="data2.icon">
                        <Option v-for="target in iconList" :value="target.value" :key="target.value">{{target.label}}</Option>
                    </Select>
                </FormItem>
                </FormItem>
            </Form>
        </Modal>
        <Row style="margin-top:20px">
            <Col span="19" class="table-form-input-select-col">
            <span class="alltitle"><router-link to="项目列表"> 项目列表</router-link>>招聘流程</span>
            </Col>
            <!--  <Col span="2" class="table-form-input-select-col">
       <span class="innertitle">下载批量表格</span>
     </Col> -->
            <!--  <Col span="2" offset="1" class="table-form-input-select-col">
       <span class="innertitle">批量导入</span>
     </Col> -->
        </Row>
        <Row class="fazhanlicheng" style="margin-top:20px;height:40px;padding-left:20px">
            <span class="title">招聘流程</span>
        </Row>
        <Row class="fazhanlicheng" style="heigh:60px;">
            <Col class="inner-info2" offset="1">时间</Col>
            <Col span="4" offset="1">
            <Input class="time-picker" placeholder="输入时间范围" style="width: 100%" v-model="progressTime" />
            </Col>
            <Col class="inner-info2" offset="2">内容</Col>
            <Col span="8" offset="1">
            <Input class="time-picker" placeholder="输入流程具体内容" style="width: 100%" v-model="progressContent" />
            </Col>
            <Col class="inner-info2" offset="2">图标</Col>
            <Col span="2" offset="1">
            <Select class="time-picker" v-model="icon" style="width:100%">
                <Option v-for="target in iconList" :value="target.value" :key="target.value">{{target.label}}</Option>
                <Avatar :src="'https://evp.51job.com/2019/51admin/icon2/icon'+icon+'.png'" slot="prefix" size="small" />
            </Select>
            </Col>
        </Row>
        <Row class="add-new-progress" style="heigh:60px;background:#f5f7f9">
            <Button type="primary" style="width:100px" @click="handleCoInfo">确认提交</Button>
        </Row>
        <div class="content-div" style="margin-top:10px">
            <Table border stripe :columns="columns2" :data="data" ref="table"></Table>
        </div>
    </div>
</template>
<script>
import {
    formatDate
} from '@/js/date.js'
export default {
    data() {
            return {
                formValidate2: {

                },
                ruleValidate2: {

                },
                data: [],
                columns2: [{
                    title: "序号",
                    key: "id",
                    width: 99,

                }, {
                    title: "时间",
                    key: "time",
                    render: (h, params) => {
                        return h('div',
                            params.row.time

                        )
                    }

                }, {
                    title: "内容",
                    key: "content",

                }, {
                    title: "图标",
                    key: "icon",
                    width: 150,

                }, {
                    title: "操作",
                    key: "action",
                    width: 99,

                    render: (h, params) => {
                        return h("div", [
                            h(
                                "span", {
                                    style: {
                                        textDecoration: "underline",
                                        color: "#4b80fd",
                                        cursor: "pointer"
                                    },
                                    on: {
                                        click: () => {
                                            this.edit(params.index);
                                        }
                                    }
                                },
                                "编辑"
                            ),
                            h(
                                "span", {
                                    style: {
                                        textDecoration: "underline",
                                        color: "#4b80fd",
                                        cursor: "pointer",
                                        'margin-left': "5px",
                                    },
                                    on: {
                                        click: () => {
                                            this.removeData(params.index);
                                        }
                                    }
                                },
                                "删除"
                            )
                        ], );
                    }
                }],
                showDataModalObject: {},
                data2: {},
                showDataModalFlag: false,
                progressTime: '',
                progressContent: '',
                icon: '1',
                iconList: [{
                    label: "offer",
                    value: "1"
                }, {
                    label: "笔试",
                    value: "2"
                }, {
                    label: "初试",
                    value: "3"
                }, {
                    label: "复试",
                    value: "4"
                }, {
                    label: "面试",
                    value: "5"
                }, {
                    label: "其他",
                    value: "6"
                }, {
                    label: "筛选",
                    value: "7"
                }, {
                    label: "体验",
                    value: "8"
                }, {
                    label: "测评",
                    value: "9"
                }, {
                    label: "申请",
                    value: "10"
                }],
                time2: ""
            }
        },
        methods: {
            removeData(index) {
                var self = this
                self.$Modal.confirm({
                    title: '确认删除？',
                    content: '',
                    onOk: () => {

                        var self = this;
                        self.$api.post('/api/v1/edit', self.data[index], function(result) {
                            self.data.splice(index, 1)
                            self.$Message.info(result.message)
                        })


                        $.ajax({
                            url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=flowdel&id=" + self.data[index].id,

                            type: "POST",
                            dataType: "json",
                            success: function(data) {

                                console.log(data);
                                self.$Message.success("删除成功！");
                                self.update()

                            }
                        });
                    },
                    onCancel: () => {
                        this.$Message.info('取消删除');
                    }
                });

            },
            edit(index) {
                this.showDataModalFlag = true;





                this.data2 = this.data[index];



                console.log(this.time2)
                console.log(this.data[index])
            },
            /*            Format(datetime, fmt) {
                            if (parseInt(datetime) == datetime) {
                                if (datetime.length == 10) {
                                    datetime = parseInt(datetime) * 1000;
                                } else if (datetime.length == 13) {
                                    datetime = parseInt(datetime);
                                }
                            }
                            datetime = new Date(datetime);
                            var o = {
                                "M+": datetime.getMonth() + 1, //月份
                                "d+": datetime.getDate(), //日
                                "h+": datetime.getHours(), //小时
                                "m+": datetime.getMinutes(), //分
                                "s+": datetime.getSeconds(), //秒
                                "q+": Math.floor((datetime.getMonth() + 3) / 3), //季度
                                "S": datetime.getMilliseconds() //毫秒
                            };
                            if (/(y+)/.test(fmt))
                                fmt = fmt.replace(RegExp.$1, (datetime.getFullYear() + "").substr(4 - RegExp.$1.length));
                            for (var k in o)
                                if (new RegExp("(" + k + ")").test(fmt))
                                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                            return fmt;
                        },*/

            handleCoInfo() {

                var poid = localStorage.pid;
                var self = this

                /*self.progressTime[0] = formatDate(new Date(self.progressTime[0]), 'yyyy-MM-dd');
                self.progressTime[1] = formatDate(new Date(self.progressTime[1]), 'yyyy-MM-dd')
                console.log(self.progressTime[0], self.progressTime[1])*/

                $.ajax({
                    url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=flowcreate&id=" + poid,
                    data: {
                        time: self.progressTime,
                        content: self.progressContent,
                        icon: self.icon
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        self.$Message.success("添加成功！");
                        self.update()

                    }
                });
            },
            handleSubmit2() {
                var self = this
                    /* self.time2[0] = formatDate(new Date(self.time2[0]), 'yyyy-MM-dd');
                     self.time2[1] = formatDate(new Date(self.time2[1]), 'yyyy-MM-dd')*/
                $.ajax({
                    url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=flowedit&id=" + self.data2.id,
                    data: {
                        content: self.data2.content,
                        icon: self.data2.icon,
                        time: self.data2.time,

                    },
                    type: "POST",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        self.$Message.success("修改成功！");
                        self.update()
                    }
                });
            },
            /*time(t) {
                var date = new Date(t),
                    Y = date.getFullYear() + "-",
                    M =
                    (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-",
                    D = date.getDate();
                return Y + M + D;
            }*/
            update() {
                var self = this;
                var poid = localStorage.pid;
                $.ajax({
                    url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=flowlist&id=" + poid,
                    type: "POST",
                    dataType: "json",
                    success: function(data) {
                        console.log(data);
                        self.data = data.data;

                    }
                });
            }
        },
        created() {
            var self = this;
            var poid = localStorage.pid;

            $.ajax({
                url: "https://evp.51job.com/51job/api/51miniadmin/back.php?action=flowlist&id=" + poid,
                type: "POST",
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    self.data = data.data;
                    /*for (var i = 0; i < data.data.length; i++) {
                        self.data[i].time = self.Format(self.data[i].time, "yyyy-MM-dd")
                        self.data[i].time_end = self.Format(self.data[i].time_end, "yyyy-MM-dd")

                    }*/

                }
            });
        }
}
</script>
<style scoped>
.innertitle {
    line-height: 30px;
    font-size: 14px;
    text-decoration: underline;
    color: #4B80FD;
    font-family: MicrosoftYaHei;
    cursor: pointer;
}

.fazhanlicheng {
    box-sizing: border-box;
    background: #fff;
    margin-bottom: 1px;
    padding: 0px;
}

.title {
    font-size: 14px;
    color: #333333;
    letter-spacing: 0;
    line-height: 40px;
    font-weight: bold;
}

.inner-info2 {
    float: left;
    line-height: 60px;
    font-size: 14px;
    color: #333;
    font-family: MicrosoftYaHei;
}

.time-picker {
    margin-top: 15px;
}

.add-new-progress {
    box-sizing: border-box;
    background: #fff;
    padding: 0;
    text-align: center;
    color: #4B80FD;
    font-family: SourceHanSansCN-Normal;
    font-size: 14px;
    line-height: 60px;
    cursor: pointer;
}
</style>
